package com.ruoyi.web.controller.api;

import cn.hutool.core.util.StrUtil;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.page.PageDomain;
import com.ruoyi.common.core.page.PageResult;
import com.ruoyi.common.core.page.ResponseResult;
import com.ruoyi.system.domain.Order;
import com.ruoyi.system.dto.ApiOrderSelectDto;
import com.ruoyi.system.service.OrderPayService;
import com.ruoyi.system.service.OrderService;
import com.ruoyi.system.vo.ApiOrderVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

@Api(tags = "开放接口---查询订单")
@RestController
@RequestMapping("api/order")
public class OrderSelectController extends BaseController {
    @Resource
    private OrderPayService orderPayService;
    @Resource
    private OrderService orderService;
    @ApiOperation(value = "查询")
    @PostMapping("/selectByType")
    public ResponseResult select(String type, PageDomain pageDomain) {

        Order order = new Order();
        order.setShowStatus(1);


        List<Order> list = orderService.findList(order, pageDomain);
        PageResult pageResult = this.getPageResult(list);
        return this.setSuccessResult(pageResult);
    }


    @ApiOperation(value = "订单查询")
    @PostMapping("/select")
    public ResponseResult<ApiOrderVo> select(@Valid @RequestBody ApiOrderSelectDto apiOrderSelectDto) {
        ApiOrderVo apiOrderVo = null;
        if (StrUtil.equals("receive", apiOrderSelectDto.getType())) {
            apiOrderVo = orderService.selectApiOrder(apiOrderSelectDto);
        } else {
            apiOrderVo = orderPayService.selectApiOrder(apiOrderSelectDto);
        }
        return this.setSuccessResult(apiOrderVo);
    }

}
